    /* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1/commercial
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may use this file in compliance with the License.
 * Alternatively, if you can't copy with the License, namely if you do not
 * want to provide source code of your modifications to this file, you may
 * negotiate a commercial licence with the initial developer.
 * You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is COID.
 *
 * The Initial Developer of the Original Code is
 * PosAm.
 * Portions created by the Initial Developer are Copyright (C) 2003
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 * Brano Kemen
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */

#ifndef __COID_SERVER_PLUGIN__HEADER_FILE__
#define __COID_SERVER_PLUGIN__HEADER_FILE__

#include "coid/comm/dynarray.h"
#include "coid/comm/str.h"
#include "serverface.h"
#include "service.h"
#include "treemgr.h"

namespace coid {

struct ttree_ifc;
////////////////////////////////////////////////////////////////////////////////
///Server plugin
struct PluginCoid : CoidNode
{
    uint        _scit;                  ///<scan iteration (psscan)
    sysDynamicLibrary _module;          ///<module where the services reside

    charstr     _path;                  ///<plugin path (full)


    typedef const ClassRegister<ServiceDescriptor>* (*t_coid_get_sdir)();

    void init( const token& name )
    {
        object_name(name);
    }

    ///Load list of services from the plugin
    opcd update_service_list( dynarray< NODEREF<ServiceCoid> >& newsvc, AcceptSvcCbk* acc );
    opcd update_core_services( dynarray< NODEREF<ServiceCoid> >& newsvc, AcceptSvcCbk* acc );
    uint load_services( t_coid_get_sdir ldr, dynarray< NODEREF<ServiceCoid> >& newsvc, AcceptSvcCbk* acc );

    opcd reload();

    static void run_services( dynarray< NODEREF<ServiceCoid> >& svc );

    PluginCoid( const token& path )
    {
        _path = path;
        _scit = 0;
		_mutex.set_name( "PluginCoid" );
    }

    opcd load()
    {
        return _module.open( _path.c_str() )
            ? ersNOERR
            : ersFAILED;
    }

    virtual token short_name() const        { static token _T("device"); return _T; }

    virtual opcd initialize()
    {
        token t = _path;
        t.cut_left_back("/\\");    //get filename
        t.cut_right_back('.');
        set_name(t);
        return 0;
    }

    virtual ~PluginCoid();

    IMPLEMENTS_VIRTUAL_INTERFACE_ttree_ifc_BEGIN_PURE(PluginCoid,"0.0",CoidNode);
    IMPLEMENTS_VIRTUAL_INTERFACE_ttree_ifc_END;
};

} // namespace coid

#endif //__COID_SERVER_PLUGIN__HEADER_FILE__
